var serverPath = location.protocol+"//"+location.hostname+':5000';
var serverAddress = location.protocol+"//"+location.hostname+':4000/';
//服务器端登录事件
var serverLoginEvent = "server.login";
//服务器端命令事件
var serverCtrlEvent = "server.ctrl";
var clientLoginBackEvent = "client.login.back";
var clientShowEvent = "client.show";
var clientCtrlEvent = "client.ctrl";

function showClientStatus(json){

    $(".client-status").each(function(){
         var $this = $(this);
         if(json.indexOf($this.data("sid"))!=-1){
             $this.css("color","blue");
         }else{
             $this.css("color","black");
         }
    });
}

function rd(n,m){
    var c = m-n+1;
    return Math.floor(Math.random() * c + n);
}

function checkImgExists(imgurl,defaultUrl) {
    var ImgObj = new Image(); //判断图片是否存在
    ImgObj.src = imgurl;
    //没有图片，则返回-1
    if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
        return imgurl;
    } else {
        return defaultUrl;
    }
}
function signInShow($p){
    //$(document).snowfall({
    //    image: "../images/snow.png",
    //    flakeCount:60,
    //    minSize: 5,
    //    maxSize: 22
    //});

    var speed 	= 500;
    var $content = $('#content',$p);
    $content.show();
    $content.html('');

    return $.get(serverAddress+"users/all",function(json){
        $.each(json,function(i){
            var el = $('<div class="user" id="img_div_'+this.id+'"><img id="img_'+this.id+'" src="photo/'+this.name+'.jpg" alt="'+this.name+'" title="'+this.name+'"><span>'+this.name+'</span></div>');
            var ch = this.ch=="1";
            if(ch){
                el.find("img").addClass("join");
                el.find("img").css({'opacity':'1.0'});
                el.find("span").css({color:"#fff"});
            }
            $content.append(el);
            el.find("img").error(function(){
                this.src = "photo/default.jpg";
            })
        });
        $content.append('<div class="placeholder"></div>');
    })
}